<template>
    <div class="container-box-container">
        <div class="flex-box flex-center justify-between flex-align-items-center">
            <div class="control-area border-radius8 flex-box flex-center flex-align-items-center" style="width:49%;">
                <div class="margin320 width-25 text-center">
                    <p class="fontSize16 color333">
                        审核通过总订单/笔
                        <!-- <el-tooltip class="item" effect="dark" content="查询时间内的审核通过订单总数，默认近30天" placement="top">
                            <div class="titleTop titleTopBorderColor2 spanLabelFontColor2">?</div>
                        </el-tooltip> -->
                    </p>
                    <p class="fontSize30 colorMain line-height55 margin0">{{statisticsObj&&statisticsObj.refundOrder ? statisticsObj.refundOrder :0}}</p>
                </div>
            </div>

            <div class="control-area border-radius8 flex-box flex-center flex-align-items-center" style="width:49%">
                <div class="margin320 width-25 text-center">
                    <p class="fontSize16 color333">
                        审核通过总金额/元
                        <!-- <el-tooltip class="item" effect="dark" content="查询时间内的审核通过订单总金额，默认近30天" placement="top">
                            <div class="titleTop titleTopBorderColor2 spanLabelFontColor2">?</div>
                        </el-tooltip> -->
                    </p>
                    <p class="fontSize30 colorMain line-height55 margin0">{{statisticsObj&&statisticsObj.refundMoney ? statisticsObj.refundMoney :0}}</p>
                </div>
            </div>
        </div>
        <Page class="main_content">
            <PageCard title="订单列表" class="margin0">
                <template #actions>
                    <el-button slot="reference" v-has="'shopping:refund:export'" class="ed-button ed_white_bottom marginRight8 ed-button36" @click="exportBtn()"><i class="el-icon-upload2"></i>导出</el-button>
                </template>
                <div class="content">
                    <div class="search_box">
                        <!-- 物业、商家 -->
                        <el-input v-if="$store.getters.type == 2 || $store.getters.type == 3 || $store.getters.type == 5" v-model="queryForm.merchantName" placeholder="请输入店铺名称" />
                        <!-- 物业 -->
                        <EdSelect v-if="$store.getters.type == 2 || $store.getters.type == 3" v-model="queryForm.channelNo" :selectParams="selectChannel"></EdSelect>

                        <!-- 平台身份 -->
                        <EdSelect v-if="$store.getters.type == 1" v-model="queryForm.productSource" :selectParams="selectSource"></EdSelect>

                        <el-input v-model="queryForm.productName" placeholder="请输入商品名称" />
                        <el-input v-model="queryForm.orderNo" placeholder="请输入订单编号" />
                        <EdSelect v-model="queryForm.refundCheck" :selectParams="selectRefundStatus"></EdSelect>
                        <!-- <EdDateTimeRange ref="timeRange" @emit-echo-time-range="emitEchoTimeDate($event, 'pickerTime')"></EdDateTimeRange> -->
                        <EdDateTimePickerRange v-model="queryForm.pickerTime"  @emit-echo-time-range="emitEchoTimeDate($event, 'pickerTime')" :pickerParams="pickerRangeParams"></EdDateTimePickerRange>
                        <el-button class="ed-button ed_black-bottom" @click="search()"><svg-icon class="svg-middle" icon-class="search-svg"/>查 询</el-button>
                        <el-button class="ed-button ed_white_bottom" @click="reset()"><svg-icon icon-class="reset-svg"/>重 置</el-button>
                    </div>
                    <ApiTable :api="load" ref="table" :params="queryForm">
                        <el-table-column type="index" width="80" label="序号"></el-table-column>
                        <el-table-column width="250" :show-overflow-tooltip="true" prop="orderNo" label="订单编号" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="orderName" label="商品名称" :formatter="formatter"></el-table-column>

                        <!-- 物业商家 -->
                        <el-table-column v-if="$store.getters.type == 2 || $store.getters.type == 3 || $store.getters.type == 5" :show-overflow-tooltip="true" prop="channelNo" label="渠道">
                            <template slot-scope="scope">
                                <span>{{returnName(scope.row['channelNo'], selectChannel.options) || scope.row['channelNo'] || '-'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="$store.getters.type == 2 || $store.getters.type == 3 || $store.getters.type == 5" :show-overflow-tooltip="true" prop="merchantName" label="店铺名称" :formatter="formatter"></el-table-column>

                        <!-- 平台 -->
                        <el-table-column v-if="$store.getters.type == 1" :show-overflow-tooltip="true" prop="productSource" label="来源">
                            <template slot-scope="scope">
                                <span>{{returnName(scope.row['productSource'], selectSource.options) || scope.row['productSource'] || '-'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="$store.getters.type == 1" :show-overflow-tooltip="true" prop="" label="客户信息">
                            <template slot-scope="scope">
                                <div>{{ scope.row.buyerName || '-'}}</div>
                                <div>{{ scope.row.buyerPhone || '-' }}</div>
                            </template>
                        </el-table-column>

                        <el-table-column :show-overflow-tooltip="true" prop="showMoney" label="订单金额">
                            <template slot-scope="scope">
                                <div v-if="scope.row['totalMoney'] && !scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元</div>
                                <div v-if="!scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalPoint'] }}积分</div>
                                <div v-if="scope.row['totalMoney'] && scope.row['totalPoint']">{{ scope.row['totalMoney'] }}元+{{ scope.row['totalPoint'] }}积分</div>
                            </template>
                        </el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="villageName" label="所属项目" :formatter="formatter"/>
                        <el-table-column :show-overflow-tooltip="true" prop="refundApplyTime" label="退款申请时间" :formatter="formatter"></el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="refundMoney" label="退款金额">
                             <template slot-scope="scope">
                                <div v-if="scope.row['refundMoney'] && !scope.row['totalPoint']">{{ scope.row['refundMoney'] }}元</div>
                                <div v-if="!scope.row['refundMoney'] && scope.row['refundPoint']">{{ scope.row['refundPoint'] }}积分</div>
                                <div v-if="scope.row['refundMoney'] && scope.row['refundPoint']">{{ scope.row['refundMoney'] }}元+{{ scope.row['refundPoint'] }}积分</div>
                            </template>
                        </el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="refundCheck" label="审核状态">
                        <template slot-scope="scope">
                            <div><span :class="['spanLabel spanLabelWidth marginRight8', 'spanLabelColor'+scope.row.refundCheck]"></span>{{returnName(scope.row['refundCheck'], selectRefundStatus.options) || scope.row['refundCheck'] || '-'}}</div>
                        </template>
                        </el-table-column>
                        <el-table-column :show-overflow-tooltip="true" prop="" label="操作" width="150">
                            <template slot-scope="scope">
                                <el-button class="ed-table-bottom ed_black_border" v-has="'shopping:refund:details'" @click="seeRow(scope.row)">查看</el-button>
                            </template>
                        </el-table-column>
                    </ApiTable>
                </div>
            </PageCard>
        </Page>
    </div>
</template>

<script>
    import EdTable from "src/components/EdTable.vue";
    import EdSelect from 'src/components/EdSelect.vue'
    import EdDateTimeRange from 'src/components/EdDateTimeRange.vue'
    import EdDateTimePickerRange from 'src/components/EdDateTimePickerRange.vue'
    import {orderList, getStaticsData, exportApi, getProjectList} from "./api";
    import Page from '../../components/Page.vue'
    import PageCard from 'src/views/components/PageCard.vue'
    import ApiTable from 'src/components/ApiTable.vue'
    import { defineComponent } from 'vue'
    import { returnName } from "src/utils/common.js";
    import { getDictByCode } from "src/api/dictionaries";
    export default defineComponent({
        name: "OrderList",
        components:{ EdTable, Page, PageCard, ApiTable, EdSelect, EdDateTimeRange, EdDateTimePickerRange },
        data(){
            return{
                queryForm:{
                    merchantName: '',
                    channelNo: '',

                    productSource: '',
                    productName: '',

                    orderNo:"",
                    refundCheck:"",
                    pickerTime: '',
                    endTime:"",
                    startTime:"",
                },
                pickerRangeParams:{
                    valueFormat:"yyyy-MM-dd HH:mm"
                },
                statisticsObj: {
                    refundOrder: 0,
                    refundMoney: 0,
                },
                selectChannel:{  // 渠道
                    placeholder:"请选择渠道",
                    options: [
                        { value: '1', label: '产品库' },
                        { value: '2', label: '线下商家' },
                    ]
                },
                selectRefundStatus:{  // 审核状态
                    placeholder:"请选择审核状态",
                    options: [
                        { value: '0', label: '通过' },
                        { value: '1', label: '不通过' },
                        { value: '2', label: '待审核' },
                    ]
                },
                selectSource:{
                    placeholder:"请选择来源",
                    options: []
                },
            }
        },
        activated(){
            // 来源
            getDictByCode('product_source').then(res=>{
                this.selectSource.options = res.data.items;
            });
            this.getStaticsData();
            this.$nextTick(()=>{
                this.$refs.table.load(1)
            })
        },
        methods:{
            load:orderList,
            getStaticsData(){
                getStaticsData({}).then(response => {
                    if(response.code == 20000) {
                        this.statisticsObj = response.data;
                    }
                })
            },
            search(){
                // if(this.queryForm.startTime){
                //     this.getStaticsData();
                // }
                // delete this.queryForm['pickerTime'];
                this.$refs.table.load(1)
            },
            reset(){
                this.queryForm = {
                    merchantName: '',
                    channelNo: '',

                    productSource: '',
                    productName: '',

                    orderNo:"",
                    refundCheck:"",
                    pickerTime: '',
                    endTime:"",
                    startTime:"",
                };
                // this.$refs.timeRange.reset();
                this.$nextTick(()=>{
                    this.$refs.table.load(1,10)
                })
            },
            seeRow(row){
                this.$router.push({
                    path: '/shopping/refund-detail',
                    query: { id: row.orderNo },
                })
            },
            // 导出
            exportBtn(){
                let page = this.$refs.table.page.total;
                if(page > 0){
                    exportApi(this.queryForm).then((res) =>{
                        // console.log('导出', res)
                    })
                }else{
                    this.$message.info({
                        message:"暂无数据导出",
                        duration: 2000,
                        center:true
                    })
                }
            },
            exportSuccess(){
                this.isEdExport = false;
            },
            returnName(val, options, value, label){
                return returnName(val, options, value, label)
            },
            emitEchoTimeDate(data){
                // $event 子组件$emit传的参数 
                this.queryForm['startTime'] = data.startTime;
                this.queryForm['endTime'] = data.endTime;
            },
            formatter(row, column, cellValue, index){
                return cellValue || '-'
            }
        }
    })
</script>

<style scoped lang="scss">
    .spanLabel{
        width: 8px;height: 8px;border-radius: 50%;display: inline-block;vertical-align: 1px
    }
    .spanLabelWidth{
        width: 6px;height: 6px;
    }
    .titleTop{
        border: 1px solid rgba(0, 0, 0, 0.65);width: 14px;height: 14px;line-height: 14px;
        border-radius: 50%;font-size: 12px;text-align: center;display: inline-block;vertical-align: 1px;margin-left: 4px;
    }

    .titleTopBorderColor1{
        border-color: rgba(0, 0, 0, 0.65);
    }
    .titleTopBorderColor2{
        border-color: #FAAD14;
    }
    .titleTopBorderColor3{
        border-color: #52C41A;
    }
    .titleTopBorderColor4{
        border-color: #1890FF;
    }
    .titleTopBorderColor5{
        border-color: #B7B7B7;
    }
    .spanLabelColor0{
        background-color: #65A9A5 !important;
    }
    .spanLabelColor2{
        background-color: #EED096 !important;
    }
    .spanLabelColor3{
        background-color: #414448 !important;
    }
    .spanLabelColor1{
        background-color: #EE7171 !important;
    }
    .colorMain{
        color: #DDB15C !important;
    }
    :deep .main_content {
        >.header{
            display:none !important;
        }
        .search_box{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 20px;
            >div{
                margin-right: 10px;
            }
        }
        .content .el-input {
            width: unset;
        }
    }
</style>